<?php

/**

 * @authors alex (20779512@qq.com)

 * @date    2014-04-15 08:58:26

 * @version 1.0

 */

namespace Admin\Controller;

class TrainCateController extends AdminController {

    

    public function index(){

    	$keyword = I('get.keyword');

    	if ($keyword != '') {

    		$map['name'] = array('like','%'.$keyword.'%');

    	}

		$obj = M('TrainCate');

		$count = $obj->where($map)->count();

		import("Common.ORG.Page");

		$page = new \Page($count, 20);

		$show = $page->show();

		$list = $obj->where($map)->order('id desc')->limit($page->firstRow . ',' . $page->listRows)->select();

		$this->assign('list', $list);

		$this->assign('page', $show);

		$this->assign('keyword', $keyword);

		$this->display();

    }



    #添加

	public function add(){

		$this->display();

	}



	#保存

	public function save(){

		$this->all_add('TrainCate',U('TrainCate/index'));

	}



	#编辑

	public function edit(){

		$id = (int) $_GET['id'];

		if (!isset ($id)) {

			$this->error('Parameter error');

		}

		$obj = M('TrainCate');



		$list = $obj->where("id=$id")->find();



		if (!$list) {

			$this->error('Information does not exist');

		} else {

			$this->assign('list', $list);

			$this->display();

		}

	}

	

	#更新

	public function update() {

		$this->all_save('TrainCate',U('TrainCate/index'));

	}



	#删除

	public function del(){



		$id=I('post.selectedids');



		if($id==''){

			$state = "You do not select any information!";

		}else{

			$obj = M('TrainCate');

			foreach ($id as $v) {

				$map['id'] = $v;				

				$obj->where($map)->delete();

			}

			$state = 'SUCCESS';

	        $message = 'Successful operation';

	        $url = U('TrainCate/index');

		}

		echo $this->echo_json_str($state,$message,$url);

	}

}